package com.gwd.task.repository;

import com.gwd.task.entity.FilesUploadEntity;
import com.gwd.task.entity.map.FileLookUpload;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zhiyongming
 * @date 2021/1/26 10:24
 */
@Repository
public interface FilesUploadRepository extends JpaRepository<FilesUploadEntity, Long> {
    @Query(value = "SELECT m.fu_id AS fuId, fu_explain AS fuExplain, file_code AS fileCode, group_id AS groupId,\n" +
            "       fu_type AS fuType, upload_time AS uploadTime, upload_user AS uploadUser, \n" +
            "       is_look_up AS isLookUp, a.original_file_name AS fileName, u.user_name AS userName \n" +
            "FROM files_upload m, file_lookup_mark d, attachment a, user_info u " +
            " WHERE d.fu_id=m.fu_id AND group_id = ?1 AND IF(?2=0,1=1,fu_type=?2) AND if(?3=1,1=1,d.is_look_up=0) AND d.user_id=?4 \n" +
            " AND a.file_name=m.file_code AND u.user_id = d.user_id order by m.fu_id desc limit ?5, ?6", nativeQuery = true)
    List<FileLookUpload> findByRead(Long groupId, Integer fuType, Integer isLookUp, Long userId, Integer pageNum, Integer pageSize);
}
